/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import algorithm.AlgorithmErrorException;

/**
 *
 * @author vermaak
 */
public class Util {
    public static double chiSquared(double[] y1, double[] y2, double[] err) throws AlgorithmErrorException {
        if (y1.length != y2.length) {
            throw new AlgorithmErrorException("Array lengths differ");
        }
        double sum=0;
        for (int i=0;i<y1.length;++i) {
            double tmp = (y1[i]-y2[i])/err[i];
            sum += tmp*tmp;
        }
        return sum;
    }
}
